# 爬取永康人才网通告
import requests
from lxml import etree
from openpyxl import Workbook

url = "http://www.zjykrc.com/"
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
                  'Chrome/69.0.3497.92 Safari/537.36 ',
    'Referer': "http://www.zjykrc.com/"
}
response = requests.get(url, headers=headers)
# response.encoding='utf-8'
xml = etree.HTML(response.text)
title_list = xml.xpath('//div[@class="tab_work_box"]/div/ul/li/a//text()')
time_list = xml.xpath('//div[@class="tab_work_box"]/div/ul/li/span/text()')
src_list = xml.xpath('//div[@class="tab_work_box"]/div/ul/li/a/@href')
for i in range(0, len(src_list)):
    src_list[i] = "http://www.zjykrc.com" + src_list[i]
book = Workbook()
sheet = book.create_sheet('永康人才网')
li = sorted(zip(time_list, title_list, src_list), reverse=True)
for i, j, k in li:
    # print(type(i+''),type(j+''),type(k))
    sheet.append([i + '', j + '', k])
if 'Sheet' in book.sheetnames:
    book.remove(book['Sheet'])
import datetime

now_time = str(datetime.datetime.now())[0:10]
title = r'永康人才网' + now_time + '.xlsx'
book.save(title)
